#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'file num_part'
exit 1
}

while getopts  ":p:f:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

num=`sed -n '$=' $1`
num_part=${num_part:=$2}
((num_sub=num/num_part))
((num_tmp=$num_part * $num_sub))

x=1
y=$num_sub
if test $num_tmp -ne $num; then 
    ((num_part-=1))
    for i in `seq $num_part`; do
        sed -n "$x,${y}p" $1  > $out_prefix.`basename $1`.$i
        ((x+=$num_sub))
        ((y+=$num_sub))
        echo $y
    done
    
    ((num_part+=1))
    sed -n "$x,${num}p" $1 > $out_prefix.`basename $1`.$num_part
    
    
else

    for i in `seq $num_part`; do
        sed -n "$x,${y}p" $1  > $out_prefix.sep.$i
        ((x+=$num_sub))
        ((y+=$num_sub))
    done

fi

. $cmd_done